/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.beans.cart;

import ecom.beans.customer.*;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;


/**
 *
 * @author Tian
 */

@NamedQueries({
  @NamedQuery(name = "findAllCarts", query = "SELECT cart FROM CartEntity cart"),
  @NamedQuery(name = "findCartById", query = "SELECT cart FROM CartEntity cart WHERE cart.id = :id")
 })
@Entity
public class CartEntity implements Serializable {
   
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private double cartTotalPrice;
    
    @OneToMany(mappedBy = "itemCart")
    private List<ItemEntity> itemEntities;

    public CartEntity() {
        
        cartTotalPrice = 0.0;
    }

    public CartEntity(Long customerId) {
        
        cartTotalPrice = 0.0;
        this.setId(customerId);
    }
    
    
    
    /**************************************************/
    
    
    public void setId(Long id) {
        this.id = id;
    }

    public List<ItemEntity> getItemEntitys() {
        return itemEntities;
    }

    public void setItemEntitys(List<ItemEntity> itemEntitys) {
        this.itemEntities = itemEntitys;
    }

    
    public Long getId() {
        return id;
    }

     public double getCartTotalPrice() {
        return cartTotalPrice;
    }

    public void setCartTotalPrice(double cartTotalPrice) {
        this.cartTotalPrice = cartTotalPrice;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CartEntity)) {
            return false;
        }
        CartEntity other = (CartEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.cart.CartEntity[id=" + id + "]";
    }

}
